/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.gui;

import javax.swing.JOptionPane;
import model.dao.DaoDisciplina;
import model.dominio.Disciplina;

/**
 *
 * @author Teao
 */
public class GuiDiscCadastrar extends javax.swing.JPanel {

    /**
     * Creates new form GuiProfCadastrar
     */
    public GuiDiscCadastrar() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        nome = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ementa = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        ch = new javax.swing.JTextField();

        setLayout(null);

        jLabel1.setText("Nome:");
        add(jLabel1);
        jLabel1.setBounds(20, 24, 50, 20);

        nome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomeActionPerformed(evt);
            }
        });
        add(nome);
        nome.setBounds(70, 20, 380, 30);

        jButton2.setText("Salvar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        add(jButton2);
        jButton2.setBounds(150, 240, 160, 50);

        jLabel3.setText("Ementa:");
        add(jLabel3);
        jLabel3.setBounds(20, 50, 60, 30);

        ementa.setColumns(20);
        ementa.setRows(5);
        jScrollPane1.setViewportView(ementa);

        add(jScrollPane1);
        jScrollPane1.setBounds(10, 80, 440, 150);

        jLabel4.setText("Carga Horária (CH):");
        add(jLabel4);
        jLabel4.setBounds(240, 50, 150, 30);

        ch.setToolTipText("");
        ch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chActionPerformed(evt);
            }
        });
        add(ch);
        ch.setBounds(380, 50, 70, 30);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Disciplina disc = new Disciplina();
        if (nome.getText().isEmpty() || ementa.getText().isEmpty() || ch.getText().isEmpty()){
            JOptionPane.showMessageDialog(this,"Digite os dados corretamente","ERRO", JOptionPane.ERROR_MESSAGE);
        }else{
            disc.setNome(nome.getText());
            disc.setEmenta(ementa.getText());
            DaoDisciplina dao = new DaoDisciplina();
            disc = (Disciplina) dao.salvar(disc);
            if(disc != null){
                JOptionPane.showMessageDialog(this,"Dados registrados com sucesso","Sucesso", JOptionPane.INFORMATION_MESSAGE);
                this.setVisible(false);
            }
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void nomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nomeActionPerformed

    private void chActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_chActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ch;
    private javax.swing.JTextArea ementa;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField nome;
    // End of variables declaration//GEN-END:variables
}
